package com.itheima.crm.service;

import java.util.ArrayList;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.itheima.common.utils.Page;

import com.itheima.crm.mapper.YuanGongDao;

import com.itheima.crm.pojo.YuanGong;
import com.itheima.crm.service.YuanGongService;

/**
 * 客户管理
 * 
 * @author lx
 *
 */
@Service
public class YuanGongServiceImpl implements YuanGongService {

	
	@Autowired
	private YuanGongDao yuangongdao;
	// 通过四个条件 查询分页对象
	public Page<YuanGong> selectPageByQueryVo(YuanGong vo) {
		Page<YuanGong> page = new Page<YuanGong>();
		// 每页数
		page.setSize(5);
		vo.setSize(5);
		if (null != vo) {
			// 判断当前页
			if (null != vo.getPage()) {
				page.setPage(vo.getPage());
				vo.setStartRow((vo.getPage() - 1) * vo.getSize());
			}

			// 总条数
			page.setTotal(yuangongdao.yuangongCountByQueryVo(vo));
			
			page.setRows(yuangongdao.selectYuanGongListByQueryVo(vo));
		}
		return page;
	}
	

	
	//通过ID查询客户
	public YuanGong selectYuanGongById(Integer id){
		return yuangongdao.selectYuanGongById(id);
	}
	
	//修改客户通过ID
	public void updateYuanGongById(YuanGong yuangong){
		yuangongdao.updateYuanGongById(yuangong);
	}
	
	//通过ID 删除客户
	public void deleteYuanGongById(Integer id){
		yuangongdao.deleteYuanGongById(id);
	}

	@Override
	public void insertYuanGong(YuanGong yuangong) {
		yuangongdao.insertYuanGong(yuangong);
		
	}

	@Override
	public void updateManagerByOrganization() {
		yuangongdao.updateManagerByOrganization();
		
	}

	@Override
	public String selectManagerByYuanGong(String yuangong) {
		return yuangongdao.selectManagerByYuanGong(yuangong);
	}

	@Override
	public Integer selectYuanGongHaveAfterDelete(String org) {
		// TODO Auto-generated method stub
		Integer selectYuanGongHaveAfterDelete = yuangongdao.selectYuanGongHaveAfterDelete(org);
		
		return selectYuanGongHaveAfterDelete;
	}

	@Override
	public void updatesRegisterMessage(YuanGong yuangong) {
		yuangongdao.updateRegisterMessage(yuangong);
		
	}

	@Override
	public YuanGong selectLogin(YuanGong yuangong) {
		// TODO Auto-generated method stub
		return yuangongdao.selectLogin(yuangong);
	}

	@Override
	public String selectYuanGongByNumber(Integer id) {
		// TODO Auto-generated method stub
		return yuangongdao.selectYuanGongByNumber(id);
	}

	@Override
	public YuanGong selectYuanGongByYGid(Integer ygid) {
		
		return yuangongdao.selectYuanGongByYGid(ygid);
	}

	@Override
	public String selectYuanGongAll(YuanGong vo) {
		// TODO Auto-generated method stub
		List<YuanGong> list=new ArrayList<YuanGong>();
		list=yuangongdao.selectAllNoPage();
		for(int i=0;i<list.size();i++) {
			System.out.println(list.get(i));
			
		}
		      
		     
		      String json = JSON.toJSONString(list);
	
		
		
		return json;
	}

	@Override
	public void updatePic(YuanGong yuangong) {
		yuangongdao.updatePic(yuangong);
		
	}

	@Override
	public Integer MaxId() {
		// TODO Auto-generated method stub
		return yuangongdao.MaxId();
	}



	@Override
	public void changeQuanXian(YuanGong yuangong) {
		yuangongdao.changeQuanXian(yuangong);
		
	}



	@Override
	public List<YuanGong> zhiweichongfu(YuanGong yuangong) {
		    List <YuanGong> a=yuangongdao.zhiweichongfu(yuangong);
		   return a;
		
			}
		     
	

	



	




}
